package com.lingnan.wanxiangxinxun.controller.user;


import com.lingnan.wanxiangxinxun.entity.po.Notice;
import com.lingnan.wanxiangxinxun.entity.vo.client.UserNoticeVO;
import com.lingnan.wanxiangxinxun.entity.vo.common.PageVO;
import com.lingnan.wanxiangxinxun.entity.vo.common.Result;
import com.lingnan.wanxiangxinxun.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 消息通知表 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-04-30
 */
@RestController("UserNoticeController")
@RequestMapping("/user/notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;


    //删除已读消息
    @DeleteMapping("/deleteReadNotice/{ids}")
    public Result deleteReadNotice(@PathVariable List<String> ids){
        boolean delete = noticeService.removeReadNotice(ids);
        if (delete) {
            return Result.success();
        }
        return Result.error("操作失败");
    }


    //标记某条消息已读（可批量已读）
    @GetMapping("/markNoticeAsRead/{ids}")
    public Result markNoticeAsRead(@PathVariable List<String> ids, @RequestParam Integer userId){
        boolean mark = noticeService.markNoticeAsRead(ids, userId);
        if (mark) {
            return Result.success();
        }
        return Result.error("操作失败");
    }


    // 分页查询某个用户的通知
    @GetMapping("/getNoticeByUserId")
    public Result getNoticeByUserId(@RequestParam Integer userId,
                                    @RequestParam(defaultValue = "1")  long current,
                                    @RequestParam(defaultValue = "10") long size){
        PageVO<UserNoticeVO> noticeList = noticeService.getNoticeByUserId(userId,current,size);
        return Result.success(noticeList);
    }


    // 分页查询全服通知
    @GetMapping("/getGlobalNotice")
    public Result getGlobalNotice(@RequestParam(defaultValue = "1") long current, @RequestParam(defaultValue = "10") long size){
        PageVO<Notice> noticeList = noticeService.getGlobalNotice(current,size);
        return Result.success(noticeList);
    }

}
